package com.evil.common.family.dto;

import cn.hutool.core.collection.CollectionUtil;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Optional;

/**
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FindByIdsReqDTO {

    /**
     * ids
     */
    @NotEmpty(message = "ids cant not empty")
    private Collection<Long> ids;

    /**
     * 是否过滤已删除
     */
    @NotNull(message = "filterDeleted cant not null")
    private Boolean filterDeleted;

    /**
     * 是否会话缓存
     */
    @NotNull(message = "cache cant not null")
    private Boolean cache;

    public Optional<FindByIdsReqDTO> check() {
        if (CollectionUtil.isNotEmpty(ids)) {
            return Optional.of(this);
        }
        return Optional.empty();
    }

    public static FindByIdsReqDTO filter(Collection<Long> ids) {
        return new FindByIdsReqDTO(ids, true, false);
    }

    public static FindByIdsReqDTO unFilter(Collection<Long> ids) {
        return new FindByIdsReqDTO(ids, false, false);
    }

    public static FindByIdsReqDTO filterCache(Collection<Long> ids) {
        return new FindByIdsReqDTO(ids, true, true);
    }

    public static FindByIdsReqDTO unFilterCache(Collection<Long> ids) {
        return new FindByIdsReqDTO(ids, false, true);
    }

    public static FindByIdsReqDTO build(Collection<Long> ids, boolean filterDeleted) {
        return new FindByIdsReqDTO(ids, true, false);
    }

    public static FindByIdsReqDTO buildCache(Collection<Long> ids, boolean filterDeleted) {
        return new FindByIdsReqDTO(ids, true, true);
    }
}
